<?php
require_once "../lib/common.php";
$response = array();

if (isset($_POST['login']) && isset ($_POST['pwd'])) {
    $employeeReturned = Login::signIn($_POST['login'], $_POST['pwd']);
    if ($employeeReturned == null) {
        Login::signOut();
    }
} else if (isset($_POST['logout'])) {
    Login::signOut();
}

$userLoggedIn = Login::getLoggedIn();
if ($userLoggedIn != null ) {
    $response["loggedInAs"] = $userLoggedIn->attributes_but(array("password"));
} else {
    $response["loggedInAs"] = null;    
}

echo json_encode($response);
?>
